<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>定时任务-添加/编辑任务</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layuimini/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/layuimini.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form layui-form-pane" action="" lay-filter="quartzForm">
            <input name="quartzId" type="hidden" th:value="${sysQuartz?.quartzId}"/>
            <div class="layui-form-item">
                <label class="layui-form-label required">任务名</label>
                <div class="layui-input-block">
                    <input type="text" name="quartzName" lay-verify="required" lay-reqtext="任务名不能为空" placeholder="请输入任务名" th:value="${sysQuartz?.quartzName}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">cron表达式</label>
                <div class="layui-input-block">
                    <input type="text" id="quartzCron" name="quartzCron" lay-verify="required" lay-reqtext="cron表达式不能为空" placeholder="请输入cron表达式" th:value="${sysQuartz?.quartzCron}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">cron含义</label>
                <div class="layui-input-block">
                    <input type="text" name="quartzCronZh" placeholder="中文含义保存后自动生成" th:value="${sysQuartz?.quartzCronZh}" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">执行类</label>
                <div class="layui-input-block">
                    <input type="text" name="quartzClass" lay-verify="required" lay-reqtext="任务执行类不能为空" placeholder="请输入任务执行类" th:value="${sysQuartz?.quartzClass}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">任务参数</label>
                <div class="layui-input-block">
                    <textarea name="quartzParam" class="layui-textarea" placeholder="请输入任务执行参数" th:text="${sysQuartz?.quartzParam}"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">任务类型</label>
                <div class="layui-input-block">
                    <select id="quartzType" name="quartzType" lay-verify="required" lay-reqtext="请选择任务类型">
                        <option value="0" th:attr="selected=${sysQuartz?.quartzType == 0 ? true : false}">内置</option>
                        <option value="1" th:attr="selected=${sysQuartz?.quartzType == 1||sysQuartz == null  ? true : false}">外配</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">任务描述</label>
                <div class="layui-input-block">
                    <textarea name="quartzDesc" class="layui-textarea" placeholder="请输入参数描述" th:text="${sysQuartz?.quartzDesc}"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">启停状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="quartzStatus" th:value="0" title="启动" th:checked="${sysQuartz?.quartzStatus==0}">
                    <input type="radio" name="quartzStatus" th:value="1" title="停止" th:checked="${sysQuartz?.quartzStatus==1}">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script th:src="@{/layuimini/lib/layui-v2.6.3/layui.js}" charset="UTF-8"></script>
<script th:src="@{/layuimini/js/lay-config.js?v=1.0.4}" charset="UTF-8"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(['form','notice', "cron"], function () {
        let form = layui.form,
            notice = layui.notice,
            cron = layui.cron,
            $ = layui.$;

        let ctxPath = /*[[@{/}]]*/'';

        //渲染Cron表达式
        cron.render({
            elem: "#quartzCron", // 绑定元素
            run: ctxPath+"develop/component/cronNextTimes", // 获取最近运行时间的接口
            done: function(cronStr) {
                console.log(cronStr);
            }
        });

        //监听表单提交按钮
        form.on('submit(saveBtn)', function (data) {
            let editFlag = [[${sysQuartz?.quartzId}]] != null ? true : false;
            let url = ctxPath+'system/sysQuartz/saveQuartz';
            let type = 'POST';
            if(editFlag){
                url = ctxPath+'system/sysQuartz/updateQuartz';
                type = 'PUT';
            }
            $.ajax({
                type:type,
                url:url,
                data:JSON.stringify(data.field),
                contentType: 'application/json;charset=utf-8;',
                dataType:'json',
                success:function (res){
                    if(res.code === 200){
                        notice.success('操作成功');
                        setTimeout(function() {
                            layer.closeAll('iframe');
                            parent.location.reload();
                        },1000);
                    }else{
                        notice.error(res.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
